var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var port = 8080;
/*
var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var fs = require('fs');
*/
//ServerConfig
server.listen(port);
app.configure(function(){
    app.use(express.static(__dirname + '/public'));
});
app.get('/', function(req, res){
    res.sendfile(__dirname + '/public/testSeiteLars.html');
});

// Websocket
io.sockets.on('connection', socketHandling);

// Portnummer in die Console schreiben
console.log('Der Server läuft nun unter http://127.0.0.1:' + port + '/');

function socketHandling(socket){
    //Client ist verbunden ggf ID zuweisen
    var p = new Person();
    console.log("neuer Client");
    socket.emit('confirmConnection', { zeit: new Date(), text: 'Verbindung erfolgreich', mensch: p });
}

function Person(){
    this.vorname = "Max";
    this.nachname = "Mustermann";
    this.eltern = ["Klaus","Maja"];
}

/*
io.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});
*/